from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['app']=r'D:\tool\apk\zuoyebang.apk'
desired_caps['appPackage']=r'com.baidu.homework'
desired_caps['appActivity']=r'com.baidu.homework.activity.init.InitActivity'
desired_caps['noReset']=False

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
sleep(3)

#点击同意
try:
    ele=driver.find_element(By.ID,'com.baidu.homework:id/iknow_alert_dialog_button2')
except Exception as e:
    print('nocancelBtn')
else:
    ele.click()
try:
#点击同意
    ele=driver.find_element(By.ID,'com.baidu.homework:id/tv_agree_click')
except Exception as e:
    print('no skipBtn')
else:
    ele.click()

try:
#点击允许
    ele=driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button')
except Exception as e:
    print('no skipBtn')
else:
    ele.click()

try:
#点击允许
    ele=driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button')
except Exception as e:
    print('no skipBtn')
else:
    ele.click()
sleep(2)
driver.find_element(By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageView').click()